package com.runfast.waimai.service.impl;

import com.runfast.common.service.BaseService;
import com.runfast.waimai.dao.model.*;
import com.runfast.waimai.service.NoticeService;
import com.runfast.waimai.service.RunfastComplainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RunfastComplainServiceImpl extends BaseService<RunfastComplain, Integer, RunfastComplainExample> implements RunfastComplainService {
    @Autowired
    private NoticeService noticeService;
    public void ComplainToNotice(){
        RunfastComplainExample example=new RunfastComplainExample();
        example.createCriteria().andHavereadEqualTo(false);
        List<RunfastComplain> runfastComplainList=this.mapper.selectByExample(example);
        if(runfastComplainList.size()>0){
            for(RunfastComplain runfastComplain:runfastComplainList){
                Notice notice=new Notice();
                notice.setTitle("用户投诉："+runfastComplain.getUserid());
                if(runfastComplain.getAgentid()!=null){
                    notice.setAgentid(runfastComplain.getAgentid());
                }else{notice.setOnlyadmin(true);}
                notice.setCreatetime(new Date());
                notice.setHaveread(false);
                notice.setDeleted(false);
                String s="<p>"+runfastComplain.getContent()+"</p><p class=\"ql-align-right ql-direction-rtl\"><strong>用户邮箱</strong>："+runfastComplain.getUseremail()+"</p>";
                notice.setContent(s);
                noticeService.insert(notice);
                runfastComplain.setHaveread(true);
                this.mapper.updateByPrimaryKeySelective(runfastComplain);
            }
        }
    }
}